﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Medical.Business;

public partial class Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Request.QueryString["type"] != null && Request.QueryString["type"].ToString() == "exit")
            {
                Session.Clear();
                Response.Redirect("Default.aspx");
            }
        }
    }
    /// <summary>
    /// 登陆
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        string strUserName = txtUserName.Text.Trim();
        if (strUserName != string.Empty)
        {
            //验证码验证
            string strCode = txtCode.Text.Trim().ToUpper();
            if (Session["WebCheckCode"]!=null && strCode == Session["WebCheckCode"].ToString())
            {
                //获取管理员信息
                BisAdminInfo bisAdminInfo = new BisAdminInfo();
                DataTable dt = bisAdminInfo.GetAdminInfo(strUserName);
                if (dt != null && dt.Rows.Count > 0)
                {
                    //验证密码
                    string strPassword = txtPassword.Text.Trim();
                    if (dt.Rows[0]["Passwords"].ToString() == Common.md5(strPassword))
                    {
                        //验证状态
                        if (!Convert.ToBoolean(dt.Rows[0]["IsLock"]))
                        {
                                //更新登陆时间
                                bisAdminInfo.SetLoginTime(Convert.ToInt32(dt.Rows[0]["ID"]));
                                //记录登陆信息
                                Session["AdminUserName"] = dt.Rows[0]["UserName"].ToString();
                                Session["AdminUserID"] = dt.Rows[0]["ID"].ToString();
                                Session["AdminName"] = dt.Rows[0]["Name"].ToString();
                                Session["AdminLoginTime"] = dt.Rows[0]["LoginTime"].ToString();
                                Session["AdminFeatures"] = dt.Rows[0]["Features"].ToString();
                                Response.Redirect("main.aspx");
                        }
                        else
                        {
                            Until.Alert("该用户已被锁定请与管理员联系！");
                            
                        }
                    }
                    else
                    {
                        Until.Alert("用户名或密码不正确！");
                    }
                    dt.Dispose();
                }
                else
                {
                    Until.Alert("用户名或密码不正确！");
                }
            }
            else
            {
                Until.Alert("验证码不正确！");
                txtCode.Focus();
            }
        }
        txtCode.Text = "";
    }
}
